// viewImagePlugin.js
import Vue from 'vue';
import ScanQrCode from './index.vue';

const Constructor = Vue.extend(ScanQrCode);
/**@type {Vue} */
let instance;
/**
 * @type {import('@/types/global').scanQrCode}
 */
const scanQrCode = function (options) {
  if (!instance) {
    instance = new Constructor({
      el: document.createElement('div')
    });
    document.body.appendChild(instance.$el);
  }
  Vue.nextTick(() => {
    instance.start(options);
  });
  return instance;
};

export default {
  install(Vue) {
    Vue.prototype.$scanQrCode = scanQrCode;
  }
};
